<?php 
    class StudentInformationBLL{
        //获取系别、年级、专业、班级
        public function getGradeMajorClass($token){
            $tokenBLL = new TokenBLL();
            $tokenInfo=$tokenBLL->getTokenInfo($token);
            if(!$tokenInfo==false){
                $publicDataBLL=new PublicDataBLL();
                if($tokenInfo['level']>=3){
                    $department=$publicDataBLL->getDepartmentList();
                    $gradeList=$publicDataBLL->getGradeList();
                    $majorList=$publicDataBLL->getMajorList();
                    $classLsit=$publicDataBLL->getClassList();
                }else{
                    $department=$publicDataBLL->getInstructorDepartment($tokenInfo['uid']);
                    $gradeList=$publicDataBLL->getInstructorGradeList($tokenInfo['uid']);
                    $majorList=$publicDataBLL->getInstructorMajorList($tokenInfo['uid']);
                    $classLsit=$publicDataBLL->getInstructorClassList($tokenInfo['uid']);
                }

                $message=array(
                    'code'=>'2001',
                    'departmentList'=>$department,
                    'gradeList'=>$gradeList,
                    'majorList'=>$majorList,
                    'classList'=>$classLsit
                );
            }else{
                $message=array(
                    'code'=>'2002',
                    'message'=>'验证已过期'
                );
            }
            return $message;
        }
        //获取学生列表
        public function getStudentList($token,$department,$grade,$major,$class,$gender,$search,$page,$pageSize){
            $tokenBLL = new TokenBLL();
            $tokenInfo=$tokenBLL->getTokenInfo($token);
            if(!$tokenInfo==false){
                $StudentInformationDAL =new StudentInformationDAL();
                if($tokenInfo['level']>=3){
                    $result=$StudentInformationDAL->getStudentList('',$department,$grade,$major,$class,$gender,$search,$page*$pageSize,$pageSize);
                }else{
                    $result=$StudentInformationDAL->getStudentList($tokenInfo['uid'],$department,$grade,$major,$class,$gender,$search,$page*$pageSize,$pageSize);
                }
                $result['count']=$this->getPage($result['count'],$pageSize);
                
                $temp=array();
                foreach($result['studentList'] as $student){
                    if($student['gender']==1){
                        $student['gender']="女";
                    }else{
                        $student['gender']="男";
                    }
                    $temp[]=$student;
                }
                $result['studentList']=$temp;
            }else{
                $message=array(
                    'code'=>'2002',
                    'message'=>'验证已过期'
                );
            }
            return $result;
        }

        //获取学生详细信息
        public function getStudentDetail($token,$studentId){
            $tokenBLL = new TokenBLL();
            $tokenInfo=$tokenBLL->getTokenInfo($token);
            if(!$tokenInfo==false){
                $StudentInformationDAL =new StudentInformationDAL();
                $studentInfo=$StudentInformationDAL->getStudentDetail($studentId);
                $dormitoryInfo=$this->getStudentDormitoryInfo($studentId);
                $studentInfo['apartment_name']=$dormitoryInfo['apartment_name'];
                $studentInfo['dormitory_id']=$dormitoryInfo['dormitory_id'];
            }else{
                $studentInfo=array(
                    'code'=>'2002',
                    'message'=>'验证已过期'
                );
            }

            return $studentInfo;
        }

        //获取学生宿舍信息
        public function getStudentDormitoryInfo($studentId){
            $StudentInformationDAL =new StudentInformationDAL();
            $dormitoryInfo=$StudentInformationDAL->getStudentDormitoryInfo($studentId);
            if($dormitoryInfo==false){
                $dormitoryInfo=array(
                    'apartment_id'=>"",
                    'apartment_name'=>"",
                    'dormitory_id'=>""
                );
            }
            return $dormitoryInfo;
        }

        public function getPage($count,$pageSize){
            $pageMax=0;
            if($count>$pageSize){
                if($count%$pageSize===0){
                    $pageMax=(int)($count/$pageSize);
                }else{
                    $pageMax=(int)($count/$pageSize)+1;
                }
            }
            
            return $pageMax;
        }
    }
?>